<?php

namespace App\Models;


use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Models\User
 *
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\User onlyTrashed()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\User withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\User withoutTrashed()
 * @mixin \Eloquent
 */
class User extends Model
{
    use SoftDeletes;

    protected $table= 't_user';

    protected $fillable = ['nick_name','face_url','passwd','email','salt','reading_num'];

    protected $dates = ['deleted_at'];

    public function bookmark(){
        return $this->hasMany(Bookmark::class, 'user_id');
    }

    public function search(){
        return $this->hasMany(SearchHistory::class, 'user_id');
    }

    public function readHistory(){
        return $this->hasMany(ReadHistory::class, 'user_id');
    }

    public function sight(){
        return $this->hasMany(Sight::class, 'user_id');
    }

    public function getTTAttribute(){
        return time().$this->face_url;
    }

    public function getFaceUrlAttribute($value){
        return ucfirst($value);
    }

    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope('id', function (Builder $builder){
            $builder->where('id', '>', 0);
        });
    }

}
